'use client'

import {useEffect} from 'react'
import {usePathname, useRouter} from 'next/navigation'

export default function ClientLayout({
  children,
}: {
  children: React.ReactNode
}) {
  const router = useRouter()
  const pathname = usePathname()

  useEffect(() => {
    const token = localStorage.getItem('token')
    
    if (pathname === '/login' && token) {
      router.replace('/home')
      return
    }
    
    if (pathname !== '/login' && !token) {
      router.replace('/login')
      return
    }

    if (pathname === '/' && token) {
      router.replace('/home')
      return
    }
  }, [pathname, router])

  return <>{children}</>
} 